/*
 * Chocolate Tunnel v0.6 Beta
 */
package Chocolate;

import network.utils.ProxyConstants;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JOptionPane;

/**
 *
 * @author Achmat Toffa
 * @email: Achmat.Toffa@gmail.com
 * 
 */
public class Settings extends javax.swing.JFrame {
    
    static int x, y; //x and y co-ordinates

    /**
     * Creates new form Settings
     */
    public Settings() {
        initComponents();
        
        text1.setText(ProxyConstants.logLevel + "");
	text2.setText(ProxyConstants.MAX_BUFFER + "");
	text3.setText(ProxyConstants.HTTPProxyHost);
	//text4.setText(ProxyConstants.SSLProxyHost);
	//text5.setText(ProxyConstants.HTTPSServer_443);
        //text6.setText(ProxyConstants.HTTPSServer_8443);
	text7.setText(ProxyConstants.HTTPSPort_443 + "");
	text8.setText(ProxyConstants.HTTPSPort_8443 + "");
	text9.setText(ProxyConstants.HTTPProxyPort + "");
	text10.setText(ProxyConstants.SSLProxyPort + "");
	text11.setText(ProxyConstants.webPHP_HOST_HTTP);
	text12.setText(ProxyConstants.webPHP_PORT_HTTP + "");
	text13.setText(ProxyConstants.webPHP_URL_HTTP);
	text14.setText(ProxyConstants.ORGANIZATION_HTTP_PROXY_HOST);
	text15.setText(ProxyConstants.ORGANIZATION_HTTP_PROXY_PORT + "");
	text16.setText(ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_NAME);
	text17.setText(ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_PASS);

	if (ProxyConstants.ENCRYPTION_ENABLED){
            chinButton.setSelected(true);
        }
	if (!ProxyConstants.ENCRYPTION_ENABLED){
            chinButton.setSelected(false);
        }

	updateField();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Settings");
        setMinimumSize(new java.awt.Dimension(300, 350));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentMoved(java.awt.event.ComponentEvent evt) {
                formComponentMoved(evt);
            }
        });

        configPanel.setMaximumSize(new java.awt.Dimension(300, 350));
        configPanel.setMinimumSize(new java.awt.Dimension(300, 350));
        configPanel.setPreferredSize(new java.awt.Dimension(300, 350));
        configPanel.setLayout(new java.awt.GridBagLayout());

        configMenuPanel.setMaximumSize(new java.awt.Dimension(300, 350));
        configMenuPanel.setMinimumSize(new java.awt.Dimension(300, 350));
        configMenuPanel.setOpaque(false);
        configMenuPanel.setPreferredSize(new java.awt.Dimension(438, 350));

        jbSave.setBackground(new java.awt.Color(44, 44, 44));
        jbSave.setForeground(new java.awt.Color(254, 254, 254));
        jbSave.setText("Save");
        jbSave.setToolTipText("Save the Configuration");
        jbSave.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jbSave.setFocusPainted(false);
        jbSave.setFocusable(false);
        jbSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jbSaveMouseExited(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jbSaveMouseEntered(evt);
            }
        });
        jbSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSaveActionPerformed(evt);
            }
        });

        jbCancel.setBackground(new java.awt.Color(44, 44, 44));
        jbCancel.setForeground(new java.awt.Color(254, 254, 254));
        jbCancel.setText("Cancel");
        jbCancel.setToolTipText("Go back without saving.");
        jbCancel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jbCancel.setFocusPainted(false);
        jbCancel.setFocusable(false);
        jbCancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jbCancelMouseExited(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jbCancelMouseEntered(evt);
            }
        });
        jbCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelActionPerformed(evt);
            }
        });

        jTabbedPane1.setBackground(new java.awt.Color(46, 46, 46));
        jTabbedPane1.setForeground(new java.awt.Color(254, 254, 254));
        jTabbedPane1.setMaximumSize(new java.awt.Dimension(300, 350));
        jTabbedPane1.setMinimumSize(new java.awt.Dimension(300, 350));
        jTabbedPane1.setPreferredSize(new java.awt.Dimension(300, 350));

        generalPanel.setBackground(new java.awt.Color(44, 44, 44));
        generalPanel.setForeground(new java.awt.Color(254, 254, 254));
        generalPanel.setMaximumSize(new java.awt.Dimension(300, 263));
        generalPanel.setMinimumSize(new java.awt.Dimension(300, 263));
        generalPanel.setPreferredSize(new java.awt.Dimension(300, 263));

        label11.setForeground(new java.awt.Color(254, 254, 254));
        label11.setText("Hoax Address");

        label12.setForeground(new java.awt.Color(254, 254, 254));
        label12.setText("Hoax Port");

        label14.setForeground(new java.awt.Color(254, 254, 254));
        label14.setText("Server Address");

        label13.setForeground(new java.awt.Color(254, 254, 254));
        label13.setText("Script Path");

        label15.setForeground(new java.awt.Color(254, 254, 254));
        label15.setText("Server Port");

        label16.setForeground(new java.awt.Color(254, 254, 254));
        label16.setText("Server Username");

        label17.setForeground(new java.awt.Color(254, 254, 254));
        label17.setText("Server Password");

        text11.setToolTipText("The network address that you are allowed to access with no restrictions.");

        text12.setToolTipText("The port of the dummy address. \n80: HTTP \n443: SSL \n8443: SSL \n22: SSH \nFor a full list of ports read the help files.\n");

        text14.setToolTipText("The IP address that will be doing  all the data forwarding to you. ");

        text13.setToolTipText("The location of the PHP script \non the server address.");

        text15.setToolTipText("The port to open to the server script. \nFor a full list of ports view the help files.");

        javax.swing.GroupLayout generalPanelLayout = new javax.swing.GroupLayout(generalPanel);
        generalPanel.setLayout(generalPanelLayout);
        generalPanelLayout.setHorizontalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPanelLayout.createSequentialGroup()
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(generalPanelLayout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(label11)
                            .addComponent(label12)
                            .addComponent(label14)
                            .addComponent(label13)
                            .addComponent(label17)
                            .addComponent(label15)))
                    .addGroup(generalPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(label16)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(text11)
                    .addComponent(text14, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addComponent(text13, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addComponent(text16, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addComponent(text17, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addGroup(generalPanelLayout.createSequentialGroup()
                        .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(text12, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(text15, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 124, Short.MAX_VALUE)))
                .addContainerGap())
        );
        generalPanelLayout.setVerticalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label11)
                    .addComponent(text11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(text12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(text14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(text13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label15)
                    .addComponent(text15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(text16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label17)
                    .addComponent(text17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(122, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("General", generalPanel);

        advancedPanel.setBackground(new java.awt.Color(44, 44, 44));
        advancedPanel.setForeground(new java.awt.Color(254, 254, 254));
        advancedPanel.setMaximumSize(new java.awt.Dimension(300, 263));
        advancedPanel.setMinimumSize(new java.awt.Dimension(300, 263));
        advancedPanel.setPreferredSize(new java.awt.Dimension(300, 263));

        label3.setForeground(new java.awt.Color(254, 254, 254));
        label3.setText("Host IP Address");

        label7.setForeground(new java.awt.Color(254, 254, 254));
        label7.setText("443 Remote Port");

        label8.setForeground(new java.awt.Color(254, 254, 254));
        label8.setText("8443 Remote Port");

        label9.setForeground(new java.awt.Color(254, 254, 254));
        label9.setText("HTTP Remote Port");

        label10.setForeground(new java.awt.Color(254, 254, 254));
        label10.setText("SSL Remote Port");

        text3.setToolTipText("Usually localhost, Ie. \"127.0.0.1\". It may be changed for fucking advanced shit.");

        text7.setToolTipText("443 SSL Remote Port");

        text8.setToolTipText("8443 SSL Remote Port");

        text9.setToolTipText("HTTP Remote Port");

        text10.setToolTipText("HTTPS(443 + 8443) Remote Port");

        javax.swing.GroupLayout advancedPanelLayout = new javax.swing.GroupLayout(advancedPanel);
        advancedPanel.setLayout(advancedPanelLayout);
        advancedPanelLayout.setHorizontalGroup(
            advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(advancedPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label9)
                    .addComponent(label10, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(label7)
                        .addComponent(label8)
                        .addComponent(label3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(text3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, advancedPanelLayout.createSequentialGroup()
                        .addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(text7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                            .addComponent(text8, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(text9, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(text10, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        advancedPanelLayout.setVerticalGroup(
            advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(advancedPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label3)
                    .addComponent(text3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label7)
                    .addComponent(text7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label8)
                    .addComponent(text8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label9)
                    .addComponent(text9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(advancedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label10)
                    .addComponent(text10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(174, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Remote", advancedPanel);

        otherPanel.setBackground(new java.awt.Color(46, 46, 46));
        otherPanel.setForeground(new java.awt.Color(254, 254, 254));
        otherPanel.setMaximumSize(new java.awt.Dimension(300, 263));
        otherPanel.setMinimumSize(new java.awt.Dimension(300, 263));
        otherPanel.setPreferredSize(new java.awt.Dimension(300, 263));

        label1.setForeground(new java.awt.Color(254, 254, 254));
        label1.setText("Log Level");

        label2.setForeground(new java.awt.Color(254, 254, 254));
        label2.setText("Max Buffer Size");

        label18.setForeground(new java.awt.Color(254, 254, 254));
        label18.setText("Enable Encryption");

        text1.setToolTipText("For data gathering, tests and debugging purposes. Set between 1 and 3.");

        text2.setToolTipText("The maximum amount of buffer bitch! Set between 0 and 30000.");

        chinButton.setBackground(new java.awt.Color(1, 1, 1));
        chinButton.setToolTipText("Ticked = Untraceable shit");

        javax.swing.GroupLayout otherPanelLayout = new javax.swing.GroupLayout(otherPanel);
        otherPanel.setLayout(otherPanelLayout);
        otherPanelLayout.setHorizontalGroup(
            otherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(otherPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(otherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label2)
                    .addComponent(label18)
                    .addComponent(label1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(otherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(text2)
                    .addGroup(otherPanelLayout.createSequentialGroup()
                        .addComponent(chinButton)
                        .addGap(0, 164, Short.MAX_VALUE))
                    .addComponent(text1))
                .addContainerGap())
        );
        otherPanelLayout.setVerticalGroup(
            otherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(otherPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(otherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label1)
                    .addComponent(text1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(otherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label2)
                    .addComponent(text2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(otherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(otherPanelLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(label18))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, otherPanelLayout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(chinButton, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(228, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Other", otherPanel);

        javax.swing.GroupLayout configMenuPanelLayout = new javax.swing.GroupLayout(configMenuPanel);
        configMenuPanel.setLayout(configMenuPanelLayout);
        configMenuPanelLayout.setHorizontalGroup(
            configMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(configMenuPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbSave, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(jbCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(configMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(configMenuPanelLayout.createSequentialGroup()
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        configMenuPanelLayout.setVerticalGroup(
            configMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, configMenuPanelLayout.createSequentialGroup()
                .addContainerGap(317, Short.MAX_VALUE)
                .addGroup(configMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbSave)
                    .addComponent(jbCancel))
                .addContainerGap())
            .addGroup(configMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        configPanel.add(configMenuPanel, new java.awt.GridBagConstraints());

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Chocolate/skullRed.jpg"))); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        configPanel.add(jLabel1, gridBagConstraints);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(configPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 350, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(configPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
                
    public void setB(){
        final String currentDir = new File("").getAbsolutePath();
        try {
            final File file = new File(currentDir + File.separator
            + "ProxyConfig.dat");
            final FileOutputStream fout = new FileOutputStream(file);
            final ObjectOutputStream obj = new ObjectOutputStream(fout);
            final HashMap store = new HashMap();
            store.put("ProxyConstants.logLevel", text1.getText().trim());
            store.put("ProxyConstants.MAX_BUFFER", text2.getText().trim());
            store.put("ProxyConstants.HTTPProxyHost", text3.getText().trim());
            store.put("ProxyConstants.SSLProxyHost", text3.getText().trim());
            store.put("ProxyConstants.HTTPSServer_443", text3.getText().trim());
            store.put("ProxyConstants.HTTPSServer_8443", text3.getText().trim());
            store.put("ProxyConstants.HTTPSPort_443", text7.getText().trim());
            store.put("ProxyConstants.HTTPSPort_8443", text8.getText().trim());
            store.put("ProxyConstants.HTTPProxyPort", text9.getText().trim());
            store.put("ProxyConstants.SSLProxyPort", text10.getText().trim());
            store.put("ProxyConstants.webPHP_HOST_HTTP", text11.getText().trim());
            store.put("ProxyConstants.webPHP_PORT_HTTP", text12.getText().trim());
            store.put("ProxyConstants.webPHP_URL_HTTP", text13.getText().trim());
            store.put("ProxyConstants.ORGANIZATION_HTTP_PROXY_HOST", text14.getText().trim());
            store.put("ProxyConstants.ORGANIZATION_HTTP_PROXY_PORT", text15.getText().trim());
            store.put("ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_NAME",text16.getText().trim());
            store.put("ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_PASS",text17.getText().trim());

            if (chinButton.isSelected()){
                store.put("ProxyConstants.ENCRYPTION_ENABLED", "Y");
            }
            if (!chinButton.isSelected()){
		store.put("ProxyConstants.ENCRYPTION_ENABLED", "N");
            }

            obj.writeObject(store);
            obj.flush();
            obj.close();
            fout.close();

            updateField();

        }
        catch (final Exception e) {
            JOptionPane.showMessageDialog(null, "Cant save configuration in : "
		+ currentDir + "ProxyConfig.dat", "Message",
		JOptionPane.ERROR_MESSAGE);
	}
    }
    public void updateField() {
    try {
        final String currentDir = new File("").getAbsolutePath();
	final File file = new File(currentDir + File.separator
		+ "ProxyConfig.dat");
	if (file.exists() && file.canRead()) {
            // Deserialize it
            final FileInputStream fin = new FileInputStream(file);
            final ObjectInputStream in = new ObjectInputStream(fin);
            final HashMap store = (HashMap) in.readObject();
            text1.setText((String) store.get("ProxyConstants.logLevel"));
            text2.setText((String) store.get("ProxyConstants.MAX_BUFFER"));
            text3.setText((String) store.get("ProxyConstants.HTTPProxyHost"));
            //text4.setText((String) store.get("ProxyConstants.SSLProxyHost"));
            //text5.setText((String) store.get("ProxyConstants.HTTPSServer_443"));
            //text6.setText((String) store.get("ProxyConstants.HTTPSServer_8443"));
            text7.setText((String) store.get("ProxyConstants.HTTPSPort_443"));
            text8.setText((String) store.get("ProxyConstants.HTTPSPort_8443"));
            text9.setText((String) store.get("ProxyConstants.HTTPProxyPort"));
            text10.setText((String) store.get("ProxyConstants.SSLProxyPort"));
            text11.setText((String) store.get("ProxyConstants.webPHP_HOST_HTTP"));
            text12.setText((String) store.get("ProxyConstants.webPHP_PORT_HTTP"));
            text13.setText((String) store.get("ProxyConstants.webPHP_URL_HTTP"));
            text14.setText((String) store.get("ProxyConstants.ORGANIZATION_HTTP_PROXY_HOST"));
            text15.setText((String) store.get("ProxyConstants.ORGANIZATION_HTTP_PROXY_PORT"));
            text16.setText((String) store.get("ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_NAME"));
            text17.setText((String) store.get("ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_PASS"));
        
            String ence = (String) store.get("ProxyConstants.ENCRYPTION_ENABLED");
            if (ence != null) {
		if (ence.equals("Y")){
                    chinButton.setSelected(true);
                }
                else{
                    chinButton.setSelected(false);
                }
            }
            // Now update the ProxyConstant file .
            String tmpStr;
           
            try {// 1
                ProxyConstants.logLevel = new Integer((String) store
                        .get("ProxyConstants.logLevel")).intValue();
            } 
            catch (Exception e1) {
            }
            try {// 2
		ProxyConstants.MAX_BUFFER = new Integer((String) store
                        .get("ProxyConstants.MAX_BUFFER")).intValue();
            } 
            catch (Exception e1) {
            }
            try {// 3
                tmpStr = (String) store.get("ProxyConstants.HTTPProxyHost");
		if (null != tmpStr){
                    ProxyConstants.HTTPProxyHost = tmpStr;
                }
            }
            catch (Exception e1) {
            }
            try {// 4
                tmpStr = (String) store.get("ProxyConstants.SSLProxyHost");
		if (null != tmpStr){
                    ProxyConstants.SSLProxyHost = tmpStr;
                }
            } 
            catch (Exception e1) {
            }
            try {// 5
                tmpStr = (String) store.get("ProxyConstants.HTTPSServer_443");
		if (null != tmpStr){
                    ProxyConstants.HTTPSServer_443 = tmpStr;
                }
            } 
            catch (Exception e1) {
            }
            try {// 6
                tmpStr = (String) store.get("ProxyConstants.HTTPSServer_8443");
                if (null != tmpStr){
                    ProxyConstants.HTTPSServer_8443 = tmpStr;
                }
            } 
            catch (Exception e1) {
            }
            try {// 7
                ProxyConstants.HTTPSPort_443 = new Integer((String) store
                        .get("ProxyConstants.HTTPSPort_443")).intValue();
            }
            catch (Exception e1) {
            }
            try {// 8
                ProxyConstants.HTTPSPort_8443 = new Integer((String) store
                        .get("ProxyConstants.HTTPSPort_8443")).intValue();
            }
            catch (Exception e1) {
            }
            try {// 9
                ProxyConstants.HTTPProxyPort = new Integer((String) store
                        .get("ProxyConstants.HTTPProxyPort")).intValue();
            }
            catch (Exception e1) {
            }
            try {// 10
                ProxyConstants.SSLProxyPort = new Integer((String) store
			.get("ProxyConstants.SSLProxyPort")).intValue();
            }
            catch (Exception e1) {
            }
            try {// 11
                tmpStr = (String) store
                        .get("ProxyConstants.webPHP_HOST_HTTP");
		if (null != tmpStr)
                    ProxyConstants.webPHP_HOST_HTTP = tmpStr;
            }
            catch (Exception e1) {
            }
            try {// 12
                ProxyConstants.webPHP_PORT_HTTP = new Integer((String) store
			.get("ProxyConstants.webPHP_PORT_HTTP")).intValue();
            }
            catch (Exception e1) {
            }
            try {// 13
                tmpStr = (String) store
                        .get("ProxyConstants.webPHP_URL_HTTP");
                if (null != tmpStr){
                    ProxyConstants.webPHP_URL_HTTP = tmpStr;
                }
            }
            catch (Exception e1) {
            }
            try {// 14
                tmpStr = (String) store.get("ProxyConstants.ORGANIZATION_HTTP_PROXY_HOST");
                if (null != tmpStr){
                    ProxyConstants.ORGANIZATION_HTTP_PROXY_HOST = tmpStr;
                }
            } 
            catch (Exception e1) {
            }
            try {// 15
                ProxyConstants.ORGANIZATION_HTTP_PROXY_PORT = new Integer((String) store
                        .get("ProxyConstants.ORGANIZATION_HTTP_PROXY_PORT")).intValue();
            }
            catch (Exception e1) {
            }
            try {// 16
                tmpStr = (String) store.get("ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_NAME");
		if (null != tmpStr){
                    ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_NAME = tmpStr;
                }
            }
            catch (Exception e1) {
            }
            try {// 17
                tmpStr = (String) store.get("ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_PASS");
                if (null != tmpStr){
                    ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_PASS = tmpStr;
                }
            }
            catch (Exception e1) {
            }
            String ence1 = (String) store.get("ProxyConstants.ENCRYPTION_ENABLED");
            if (ence1 != null) {
                if (ence1.equals("Y")){
                    ProxyConstants.ENCRYPTION_ENABLED = true;
                }
                else{
                    ProxyConstants.ENCRYPTION_ENABLED = false;
                }
            }

	
            in.close();
            fin.close();
	}
    } 
    catch (final Exception e) {
        System.out.println(e.getMessage());
        // e.printStackTrace();
    }
    }

    private void jbCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_jbCancelActionPerformed

    private void jbSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSaveActionPerformed
        final String currentDir = new File("").getAbsolutePath();
		try {
                    final File file = new File(currentDir + File.separator
                    		+ "ProxyConfig.dat");
                    final FileOutputStream fout = new FileOutputStream(file);
                    final ObjectOutputStream obj = new ObjectOutputStream(fout);
                    final HashMap store = new HashMap();
                    store.put("ProxyConstants.logLevel", text1.getText().trim());
                    store.put("ProxyConstants.MAX_BUFFER", text2.getText().trim());
                    store.put("ProxyConstants.HTTPProxyHost", text3.getText().trim());
                    store.put("ProxyConstants.SSLProxyHost", text3.getText().trim());
                    store.put("ProxyConstants.HTTPSServer_443", text3.getText().trim());
                    store.put("ProxyConstants.HTTPSServer_8443", text3.getText().trim());
                    store.put("ProxyConstants.HTTPSPort_443", text7.getText().trim());
                    store.put("ProxyConstants.HTTPSPort_8443", text8.getText().trim());
                    store.put("ProxyConstants.HTTPProxyPort", text9.getText().trim());
                    store.put("ProxyConstants.SSLProxyPort", text10.getText().trim());
                    store.put("ProxyConstants.webPHP_HOST_HTTP", text11.getText().trim());
                    store.put("ProxyConstants.webPHP_PORT_HTTP", text12.getText().trim());
                    store.put("ProxyConstants.webPHP_URL_HTTP", text13.getText().trim());
                    store.put("ProxyConstants.ORGANIZATION_HTTP_PROXY_HOST", text14
                                        .getText().trim());
                    store.put("ProxyConstants.ORGANIZATION_HTTP_PROXY_PORT", text15
					.getText().trim());
                    store.put("ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_NAME",
					text16.getText().trim());
                    store.put("ProxyConstants.ORGANIZATION_HTTP_PROXY_USER_PASS",
					text17.getText().trim());

                    if (chinButton.isSelected()){
                        store.put("ProxyConstants.ENCRYPTION_ENABLED", "Y");
                    }
                    if (!chinButton.isSelected()){
                        store.put("ProxyConstants.ENCRYPTION_ENABLED", "N");
                    }
                    obj.writeObject(store);
                    obj.flush();
                    obj.close();
                    fout.close();
                    updateField();

                } 
                catch (final Exception e) {
                    JOptionPane.showMessageDialog(null, "Cant save configuration in : "
				+ currentDir + "ProxyConfig.dat", "Message",
                                JOptionPane.ERROR_MESSAGE);
		}
        this.dispose();
    }//GEN-LAST:event_jbSaveActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        MainUI.jbFormVisible.doClick();
    }//GEN-LAST:event_formWindowClosed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        setLocation(MainUI.x, MainUI.y);
    }//GEN-LAST:event_formWindowOpened

    private void formComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentMoved
        x = getX();
        y = getY();
    }//GEN-LAST:event_formComponentMoved

    private void jbSaveMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbSaveMouseEntered
        MainUI.colourLooper = 1;
        MainUI.whichButton = jbSave.getText();
        (new MainUI.Looper()).start();
    }//GEN-LAST:event_jbSaveMouseEntered

    private void jbSaveMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbSaveMouseExited
        MainUI.colourLooper = 2;
        
        try {
            Thread.sleep(10);
            jbSave.setBackground(new java.awt.Color(44,44,44));
        } 
        catch (InterruptedException ex) {
            Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jbSaveMouseExited

    private void jbCancelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbCancelMouseEntered
        MainUI.colourLooper = 1;
        MainUI.whichButton = jbCancel.getText();
        (new MainUI.Looper()).start();
    }//GEN-LAST:event_jbCancelMouseEntered

    private void jbCancelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbCancelMouseExited
        MainUI.colourLooper = 2;
        
        try {
            Thread.sleep(10);
            jbCancel.setBackground(new java.awt.Color(44,44,44));
        } 
        catch (InterruptedException ex) {
            Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jbCancelMouseExited

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Settings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Settings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Settings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Settings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Settings().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static final javax.swing.JPanel advancedPanel = new javax.swing.JPanel();
    public static final javax.swing.JCheckBox chinButton = new javax.swing.JCheckBox();
    public static final javax.swing.JPanel configMenuPanel = new javax.swing.JPanel();
    public static final javax.swing.JPanel configPanel = new javax.swing.JPanel();
    public static final javax.swing.JPanel generalPanel = new javax.swing.JPanel();
    public static final javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
    public static final javax.swing.JTabbedPane jTabbedPane1 = new javax.swing.JTabbedPane();
    public static final javax.swing.JButton jbCancel = new javax.swing.JButton();
    public static final javax.swing.JButton jbSave = new javax.swing.JButton();
    public static final javax.swing.JLabel label1 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label10 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label11 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label12 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label13 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label14 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label15 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label16 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label17 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label18 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label2 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label3 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label7 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label8 = new javax.swing.JLabel();
    public static final javax.swing.JLabel label9 = new javax.swing.JLabel();
    public static final javax.swing.JPanel otherPanel = new javax.swing.JPanel();
    public static final javax.swing.JTextField text1 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text10 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text11 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text12 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text13 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text14 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text15 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text16 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text17 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text2 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text3 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text7 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text8 = new javax.swing.JTextField();
    public static final javax.swing.JTextField text9 = new javax.swing.JTextField();
    // End of variables declaration//GEN-END:variables
}
